{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "pop_df=pd.read_csv(r'C:\\Users\\Yasaman\\Downloads\\World_bank_population.csv',skiprows=3)\n",
    "pop_df=pop_df[['Country Code','2002','2019']].dropna()\n",
    "pop_df['2019']=pop_df['2019'].astype(int)\n",
    "possible_countries=pop_df.query(\" `2019` >=1000000\")['Country Code'].values\n",
    "possible_countries=[x.lower() for x in possible_countries]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Median  2002:  8400180.0 ----2019:  9054000.0\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Country Code</th>\n",
       "      <th>2002</th>\n",
       "      <th>2019</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>BHR</td>\n",
       "      <td>710553.0</td>\n",
       "      <td>1483756</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>KWT</td>\n",
       "      <td>2059974.0</td>\n",
       "      <td>4442316</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>OMN</td>\n",
       "      <td>2337140.0</td>\n",
       "      <td>4591241</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>LBY</td>\n",
       "      <td>5508410.0</td>\n",
       "      <td>6951033</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>JOR</td>\n",
       "      <td>5616066.0</td>\n",
       "      <td>10671891</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>TUN</td>\n",
       "      <td>9971515.0</td>\n",
       "      <td>11875081</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>SYR</td>\n",
       "      <td>17468332.0</td>\n",
       "      <td>20353534</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>YEM</td>\n",
       "      <td>20835086.0</td>\n",
       "      <td>35111408</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>MAR</td>\n",
       "      <td>29198142.0</td>\n",
       "      <td>36210898</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>EGY</td>\n",
       "      <td>76239137.0</td>\n",
       "      <td>107553158</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  Country Code        2002       2019\n",
       "0          BHR    710553.0    1483756\n",
       "1          KWT   2059974.0    4442316\n",
       "2          OMN   2337140.0    4591241\n",
       "3          LBY   5508410.0    6951033\n",
       "4          JOR   5616066.0   10671891\n",
       "5          TUN   9971515.0   11875081\n",
       "6          SYR  17468332.0   20353534\n",
       "7          YEM  20835086.0   35111408\n",
       "8          MAR  29198142.0   36210898\n",
       "9          EGY  76239137.0  107553158"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Country_list={'Egypt':'EGY', 'Tunisia':'TUN','Libya':'LBY','Syria':'SYR','Yemen':'YEM','Bahrain':'BHR','Jordan':'JOR','Kuwait':'KWT','Morocco':'MAR','Oman':'OMN'}\n",
    "rev_Country_list={Country_list[key]: key for key in Country_list}\n",
    "abbr=[country for country in Country_list.values()]\n",
    "table=pop_df[pop_df['Country Code'].isin(abbr)].sort_values('2002')\n",
    "print(\"Median\", ' 2002: ',pop_df['2002'].median(),'----2019: ',pop_df['2019'].median())\n",
    "table.reset_index(drop=True)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
